package examples.color_picker.views;


import divtastic.js.DisplayDiv;
import divtastic.js.Divtastic;
import divtastic.js.Drawing;
import divtastic.js.application.views.WindowView;
import divtastic.js.GradientFiller;
import divtastic.js.application.views.ColorHexagon;
import divtastic.Enumerables;
using divtastic.js.Drawing;

class HexagonPickerView
{
    
    
    
    private var _holder:        DisplayDiv;
    private var _win:           WindowView;
    private var _enabled:       Bool;
    private var _gradFiller:    GradientFiller;
    private var _selectColor:   Int;
    
    
    public function new(    holder_     : DisplayDiv
                        ,   win_        : WindowView
                        ,   firstColor  : ColorPallet
                        ,   secondColor : ColorPallet
                        ,   selectColor : Int
                        )
    {
        
        _enabled    = true ;
        _holder     = holder_ ;
        _win        = win_ ;
        _selectColor = selectColor;
        _gradFiller = new GradientFiller( null );
        var arrHex  = new ColorHexagon  (   holder_
                                        ,   50 
                                        ,   65 + WindowView.headerHeight
                                        ,   15
                                        ,   12
                                        ,   firstColor
                                        ,   secondColor
                                        ,   Horizontal
                                        ) ;
        
        for( i in 0...arrHex.hexagons.length )
        {
            
            var colHex = arrHex.hexagons[ i ];
            
            colHex.div.setOver( 
                                        callback( hexSelected, colHex ) 
                                    );
            colHex.div.setOut( 
                                        callback( hexOut, colHex ) 
                                    );
            colHex.div.setPress(
                                        toggleEnable
                                        );
                                        
            colHex.div.getStyle().cursor = "pointer";
            
        }
        
    }
    
    
    public function toggleEnable()
    {
        
        _enabled = !_enabled;
        
    }
    
    
    public function hexSelected( colHex: ColorHex )
    {
        
        if( _enabled )
        {
            
            _win.set_fill( colHex.firstColor );
            _gradFiller.setGrads( colHex.hexGrad );
            _gradFiller.fill( _selectColor );
            
        }
        
    }
    
    public function hexOut(  colHex: ColorHex )
    {
        
        _gradFiller.setGrads( colHex.hexGrad );
        _gradFiller.fill( colHex.secondColor,colHex.firstColor );
        
    }
    
}